1 Git命令自动补全

  • 找到 git-completion.bash

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # 得到git completion脚本,拷贝一份放到自己的位置
    find / -name git-completion.bash

    # 将脚本加入用户bash环境变量
    vim ~/.bashrc

    # 填入内容并保存
    . PATH_TO_git-completion.bash

    # 使配置生效,而不用重启或者重新登录
    source ~/.bashrc
  • 输入git 然后用tab补全

2 Git显示分支信息

  • 同样的方法和路径找到git-prompt.sh

  • 在同样的文件中加入.bashrc 内容如下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # Git AutoComplete
    . ~/CustomScripts/git-completion.bash

    # Git Prompt
    . ~/CustomScripts/git-prompt.sh
    export GIT_PS1_SHOWDIRTYSTATE=1
    export GIT_PS1_SHOWSTASHSTATE=1
    export GIT_PS1_SHOWUNTRACKEDFILES=1
    export GIT_PS1_SHOWUPSTREAM="auto"
    export GIT_PS1_SHOWCOLORHINTS=1
    export PS1='\w$(__git_ps1 " (%s)")\$ '

3 Bash 终端设置显示颜色

  • 执行命令

    1
    2
    brew install xz coreutils
    gdircolors --print-database > ~/.dir_colors

  • 编辑 ~/.bash_profile 并加入如下内容

    1
    2
    3
    4
    5
    6
    7
    8
    if brew list | grep coreutils > /dev/null ; then
    PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH"
    alias ls='ls -F --show-control-chars --color=auto'
    eval `gdircolors -b $HOME/.dir_colors`
    fi
    alias grep='grep --color'
    alias egrep='egrep --color'
    alias fgrep='fgrep --color'

4 VIM 设置

  • 编辑.vimrc

    1
    2
    3
    4
    5
    6
    7
    syntax on
    set nu
    set tabstop=4
    set softtabstop=4
    set autoindent
    set cindent
    set ruler

5 Bash 命令提示符显示颜色

 习惯了gitbash 的彩色,在这里面用着总是不舒服,设置一个彩色的命令提示符。

  • 编辑.bashrc

    1
    export PS1='\n\[\033[32m\]\u@\h\[\033[33m\]\w\[\33[36m\]$(__git_ps1 " (%s)") \[\033[0m\]\n\$ '

最后更新: 2022年03月02日 03:32

原始链接: http://rawbin-.github.io/dev-env/2016-04-02-custom-bash/

× 赞赏这个人~
打赏二维码